/*
Run this script on:

        mssql-ct.db.jwan.it,1433.Caronte2013    -  This database will be modified

to synchronize it with:

        kalgan01.cs.jwan.it,1443.Jambo2014_sviluppo

You are recommended to back up your database before running this script

Script created by SQL Compare version 9.0.0 from Red Gate Software Ltd at 10/04/2014 15:07:41

*/
SET NUMERIC_ROUNDABORT OFF
GO
SET ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, ARITHABORT, QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE id=OBJECT_ID('tempdb..#tmpErrors')) DROP TABLE #tmpErrors
GO
CREATE TABLE #tmpErrors (Error int)
GO
SET XACT_ABORT ON
GO
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
GO
BEGIN TRANSACTION
GO
PRINT N'Creating [dbo].[fn_jb_check_abbonamenti_validi]'
GO
-- =====================================================================
-- Author:		Andrea Marchesini
-- Create date: 2012-09-18
-- Description:	Controlla che non ci siano rinnovi abbonamenti 
--  validi per la tessera nel periodo specificato
-- =====================================================================
CREATE FUNCTION [dbo].[fn_jb_check_abbonamenti_validi] 
(
	@id_tessera int,
	@from date
)
RETURNS bit
WITH ENCRYPTION AS
BEGIN
	DECLARE @c int
		
	SELECT @c= ISNULL((SELECT count(*) FROM jb_abbonamenti WHERE @id_tessera=id_tessera AND @from <= data_fine AND annullato=0),0)

	IF @c>0
		RETURN 1
	
	RETURN 0

END
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating [dbo].[jb_remote_clienti]'
GO
CREATE TABLE [dbo].[jb_remote_clienti]
(
[IDCLIENTE_REMOTE] [int] NOT NULL IDENTITY(1, 1),
[CODCLIENTE_EXT] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[CODCOMP] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[NOME] [nvarchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[COGNOME] [nvarchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[INDIRIZZO] [nvarchar] (60) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[CITTA] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[EMAIL] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[TELEFONO] [nvarchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[CODICEFISCALE] [varchar] (16) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[PIVA] [varchar] (16) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[DATA_NASCITA] [smalldatetime] NULL,
[LUOGO_NASCITA] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[NAZIONE] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[NOTE] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
)
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating primary key [PK_jb_remote_clienti] on [dbo].[jb_remote_clienti]'
GO
ALTER TABLE [dbo].[jb_remote_clienti] ADD CONSTRAINT [PK_jb_remote_clienti] PRIMARY KEY CLUSTERED  ([IDCLIENTE_REMOTE])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating [dbo].[jb_stampe]'
GO
CREATE TABLE [dbo].[jb_stampe]
(
[CODICE_STAMPA] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[DESCRIZIONE] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
)
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating primary key [PK__jb_stampe] on [dbo].[jb_stampe]'
GO
ALTER TABLE [dbo].[jb_stampe] ADD CONSTRAINT [PK__jb_stampe] PRIMARY KEY NONCLUSTERED  ([CODICE_STAMPA])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating [dbo].[jb_remote_abbonamenti_itiner]'
GO
CREATE TABLE [dbo].[jb_remote_abbonamenti_itiner]
(
[CODITINER_LOCAL] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[CODITINER_REMOTE] [nvarchar] (25) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[CODCOMP] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
)
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating primary key [PK_remote_jb_itinerabb] on [dbo].[jb_remote_abbonamenti_itiner]'
GO
ALTER TABLE [dbo].[jb_remote_abbonamenti_itiner] ADD CONSTRAINT [PK_remote_jb_itinerabb] PRIMARY KEY CLUSTERED  ([CODITINER_REMOTE], [CODCOMP])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating [dbo].[jb_remote_abbonamenti_porti]'
GO
CREATE TABLE [dbo].[jb_remote_abbonamenti_porti]
(
[CODPORTO_LOCAL] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[CODPORTO_REMOTE] [nvarchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[CODCOMP] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
)
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating primary key [PK_remote_jb_portiabb] on [dbo].[jb_remote_abbonamenti_porti]'
GO
ALTER TABLE [dbo].[jb_remote_abbonamenti_porti] ADD CONSTRAINT [PK_remote_jb_portiabb] PRIMARY KEY CLUSTERED  ([CODPORTO_REMOTE], [CODCOMP])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating [dbo].[fn_jb_isCARTA]'
GO
SET ANSI_NULLS OFF
GO
CREATE FUNCTION [dbo].[fn_jb_isCARTA](@formapag nvarchar(5))
RETURNS bit 
--WITH ENCRYPTION
WITH ENCRYPTION AS
begin
declare @res bit
SELECT @res=CARTACREDITO FROM PAGAME WHERE formapag=@formapag
return @res
end
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating [dbo].[fn_jb_isCONTANTI]'
GO
CREATE FUNCTION [dbo].[fn_jb_isCONTANTI](@formapag nvarchar(5))
RETURNS bit 
--WITH ENCRYPTION
WITH ENCRYPTION AS
begin
declare @res bit
SELECT @res=CASH FROM PAGAME WHERE formapag=@formapag
return @res
end
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating [dbo].[fn_jb_isVOUCHER]'
GO
CREATE FUNCTION [dbo].[fn_jb_isVOUCHER](@formapag nvarchar(5))
RETURNS bit 
--WITH ENCRYPTION
WITH ENCRYPTION AS
begin
declare @res bit
SELECT @res=VOUCHER FROM PAGAME WHERE formapag=@formapag
return @res
end
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating [dbo].[fn_jb_tessere_check_itiner_porti]'
GO
SET ANSI_NULLS ON
GO

-- =============================================
-- Author:		Andrea Marchesini
-- Create date: 2012-09-18
-- Description:	Controlla se il codici associati alla tessera sono
--	porti o itinerari validi
-- =============================================
CREATE FUNCTION [dbo].[fn_jb_tessere_check_itiner_porti](
	@iti_port char(4)
)
RETURNS bit
WITH ENCRYPTION AS
BEGIN
	
	declare @c int
	
	select @c=isnull((select count(*) from itiner where coditinera = @iti_port),0)
	
	if @c > 0
		return 1
	
	select @c=isnull((select count(*) from porti where codporto = @iti_port),0)
	
	if @c > 0
		return 1
		
	return 0
END
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating [dbo].[fn_jb_config_value]'
GO
-- =============================================
-- Author:	Andrea Marchesini
-- Create date: 2012-09-25
-- Description:	Restituisce il valore della chiave di configurazione specificata
-- =============================================
CREATE FUNCTION [dbo].[fn_jb_config_value]
(
	@chiave nvarchar(50)
)
RETURNS nvarchar(100)
WITH ENCRYPTION AS
BEGIN
	RETURN (
		SELECT valore 
		FROM jb_personalizzazioni
		WHERE chiave = @chiave
	)

	
END
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating [dbo].[jb_voucher]'
GO
CREATE TABLE [dbo].[jb_voucher]
(
[IDVOUCHER] [int] NOT NULL IDENTITY(1, 1),
[PROT_AGE] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[CODAGE] [varchar] (6) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[IS_MODIFICABILE] [bit] NOT NULL DEFAULT ((1)),
[IS_OPZIONE] [bit] NOT NULL DEFAULT ((0)),
[UTILIZZATO] [bit] NOT NULL DEFAULT ((0)),
[DATA_INSERIMENTO] [datetime] NOT NULL DEFAULT (getdate()),
[DATA_ANNULLAMENTO] [datetime] NULL,
[NOTE] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[LAST_MINUTE] [bit] NOT NULL DEFAULT ((0))
)
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating primary key [PK_jb_voucher] on [dbo].[jb_voucher]'
GO
ALTER TABLE [dbo].[jb_voucher] ADD CONSTRAINT [PK_jb_voucher] PRIMARY KEY CLUSTERED  ([IDVOUCHER])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating [dbo].[fn_get_ivappl_comm]'
GO
CREATE FUNCTION [dbo].[fn_get_ivappl_comm](
@codpren char(14),
@n_seq int,
@n_mod int)
RETURNS decimal(18,2)
--WITH ENCRYPTION
 WITH ENCRYPTION AS  
BEGIN 

DECLARE @aliquota decimal(18,2)

  SELECT TOP(1) @aliquota=ivaappl
  FROM commissioni_dett AS co
  where co.CODPREN=@codpren
  and co.N_SEQ=@n_seq
  and co.N_MOD=@n_mod
  
  -- se nn ci sono record in commissioni_dett recupero l'iva da itiner
  if (@aliquota is null)
  begin
    select @aliquota=i.IVAAPPL from itiner i
    inner join seqbig s on i.CODITINERA = s.CODITINERA
    where s.CODPREN=@codpren
    and s.N_SEQ=@n_seq
    and s.N_MOD=@n_mod
  end
  
  SELECT @aliquota = ISNULL(@aliquota,0)




RETURN @aliquota
end
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating [dbo].[jb_remote_abbonamenti_passaggi]'
GO
CREATE TABLE [dbo].[jb_remote_abbonamenti_passaggi]
(
[ID] [int] NOT NULL,
[ID_TESSERA] [int] NOT NULL,
[CODCOMP] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[TIPOMOV] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[CODITINERA] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[DATAMOV] [datetime] NOT NULL,
[DATAUPD] [datetime] NOT NULL DEFAULT (getdate()),
[DA_RIMUOVERE] [bit] NOT NULL DEFAULT ((0))
)
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating primary key [PK_jb_remote_abbonamenti_passaggi] on [dbo].[jb_remote_abbonamenti_passaggi]'
GO
ALTER TABLE [dbo].[jb_remote_abbonamenti_passaggi] ADD CONSTRAINT [PK_jb_remote_abbonamenti_passaggi] PRIMARY KEY CLUSTERED  ([ID])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Adding constraints to [dbo].[jb_remote_clienti]'
GO
ALTER TABLE [dbo].[jb_remote_clienti] ADD CONSTRAINT [UNIQUE_CLIENTE_REMOTE] UNIQUE NONCLUSTERED  ([CODCLIENTE_EXT], [CODCOMP])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Adding foreign keys to [dbo].[jb_remote_abbonamenti_itiner]'
GO
ALTER TABLE [dbo].[jb_remote_abbonamenti_itiner] ADD
CONSTRAINT [FK_jb_remote_abbonamenti_itiner_itiner] FOREIGN KEY ([CODITINER_LOCAL]) REFERENCES [dbo].[itiner] ([CODITINERA]),
CONSTRAINT [FK_jb_remote_abbonamenti_itiner_compagnie] FOREIGN KEY ([CODCOMP]) REFERENCES [dbo].[compagnie] ([CODCOMP])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Adding foreign keys to [dbo].[jb_remote_abbonamenti_passaggi]'
GO
ALTER TABLE [dbo].[jb_remote_abbonamenti_passaggi] ADD
CONSTRAINT [FK_jb_remote_abbonamenti_passaggi_jb_tessere] FOREIGN KEY ([ID_TESSERA]) REFERENCES [dbo].[jb_tessere] ([ID_TESSERA]),
CONSTRAINT [FK_jb_remote_abbonamenti_passaggi_compagnie] FOREIGN KEY ([CODCOMP]) REFERENCES [dbo].[compagnie] ([CODCOMP]),
CONSTRAINT [FK_jb_remote_abbonamenti_passaggi_causalimovim] FOREIGN KEY ([TIPOMOV]) REFERENCES [dbo].[causalimovim] ([TIPOMOV]),
CONSTRAINT [FK_jb_remote_abbonamenti_passaggi_itiner] FOREIGN KEY ([CODITINERA]) REFERENCES [dbo].[itiner] ([CODITINERA])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Adding foreign keys to [dbo].[jb_remote_abbonamenti_porti]'
GO
ALTER TABLE [dbo].[jb_remote_abbonamenti_porti] ADD
CONSTRAINT [FK_jb_remote_abbonamenti_porti_porti] FOREIGN KEY ([CODPORTO_LOCAL]) REFERENCES [dbo].[porti] ([CODPORTO]),
CONSTRAINT [FK_jb_remote_abbonamenti_porti_compagnie] FOREIGN KEY ([CODCOMP]) REFERENCES [dbo].[compagnie] ([CODCOMP])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Adding foreign keys to [dbo].[jb_remote_clienti]'
GO
ALTER TABLE [dbo].[jb_remote_clienti] ADD
CONSTRAINT [FK_jb_remote_clienti_compagnie] FOREIGN KEY ([CODCOMP]) REFERENCES [dbo].[compagnie] ([CODCOMP])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Adding foreign keys to [dbo].[jb_voucher]'
GO
ALTER TABLE [dbo].[jb_voucher] ADD
CONSTRAINT [FK_jb_voucher_agenzi] FOREIGN KEY ([CODAGE]) REFERENCES [dbo].[agenzi] ([CODAGE])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating extended properties'
GO
EXEC sp_addextendedproperty N'MS_Description', N'Nome WS', 'SCHEMA', N'dbo', 'TABLE', N'jb_stampe', 'COLUMN', N'CODICE_STAMPA'
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering permissions on [dbo].[fn_get_ivappl_comm]'
GO
GRANT EXECUTE ON  [dbo].[fn_get_ivappl_comm] TO [JamboClient]
GRANT EXECUTE ON  [dbo].[fn_get_ivappl_comm] TO [JamboGest]
GO
PRINT N'Altering permissions on [dbo].[jb_remote_abbonamenti_itiner]'
GO
GRANT SELECT ON  [dbo].[jb_remote_abbonamenti_itiner] TO [JamboClient]
GRANT INSERT ON  [dbo].[jb_remote_abbonamenti_itiner] TO [JamboClient]
GRANT DELETE ON  [dbo].[jb_remote_abbonamenti_itiner] TO [JamboClient]
GRANT UPDATE ON  [dbo].[jb_remote_abbonamenti_itiner] TO [JamboClient]
GO
PRINT N'Altering permissions on [dbo].[jb_remote_abbonamenti_passaggi]'
GO
GRANT INSERT ON  [dbo].[jb_remote_abbonamenti_passaggi] TO [sync_abb]
GRANT SELECT ON  [dbo].[jb_remote_abbonamenti_passaggi] TO [sync_jb_abbonamenti]
GRANT INSERT ON  [dbo].[jb_remote_abbonamenti_passaggi] TO [sync_jb_abbonamenti]
GO
PRINT N'Altering permissions on [dbo].[jb_remote_abbonamenti_porti]'
GO
GRANT SELECT ON  [dbo].[jb_remote_abbonamenti_porti] TO [JamboClient]
GRANT INSERT ON  [dbo].[jb_remote_abbonamenti_porti] TO [JamboClient]
GRANT DELETE ON  [dbo].[jb_remote_abbonamenti_porti] TO [JamboClient]
GRANT UPDATE ON  [dbo].[jb_remote_abbonamenti_porti] TO [JamboClient]
GO
PRINT N'Altering permissions on [dbo].[jb_stampe]'
GO
GRANT SELECT ON  [dbo].[jb_stampe] TO [JamboClient]
GRANT SELECT ON  [dbo].[jb_stampe] TO [JamboGest]
GRANT INSERT ON  [dbo].[jb_stampe] TO [JamboGest]
GRANT DELETE ON  [dbo].[jb_stampe] TO [JamboGest]
GRANT UPDATE ON  [dbo].[jb_stampe] TO [JamboGest]
GO
IF EXISTS (SELECT * FROM #tmpErrors) ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT>0 BEGIN
PRINT 'The database update succeeded'
COMMIT TRANSACTION
END
ELSE PRINT 'The database update failed'
GO
DROP TABLE #tmpErrors
GO
